[r447]: / trunk / mqttsparkplugb / mqttsparkplugb / SparkplugB / Function Blocks / FB_Payload / FB_PayloadMetric / svnobj  Maximize  Restore  History

Download this file

91 lines (89 with data), 40.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
ELSIF NOT xDecode AND NOT xEncode THEN //DO NOTHING, ALL OUTPUTS OFF
	xDecodeError:=FALSE;
	eDecodeError := ERROR.NO_ERROR;
	xEncodeError:=FALSE;
	eEncodeError := ERROR.NO_ERROR;
ELSIF xDecode AND NOT xEncode THEN //Decode
	xDecodeBusy:=TRUE;
ELSIF NOT xDecode AND xEncode THEN //Encode
	xEncodeBusy:=TRUE;
END_IF%
IF xDecodeBusy THEN
	InitializeStructure();
	
	eDecodeState := PayloadDecodeStates.object_getlength;
	//decode length
	FOR ProtobufBlobIndex := ProtobufBlobIndex TO finalByteIndex DO
		CASE eDecodeState OF
		PayloadDecodeStates.object_getmember:
			CASE myProtobufBlob[ProtobufBlobIndex] OF
			16#00://end of data? padding byte? ERROR
				xDecodeError := TRUE;
				eDecodeError := ERROR.PayloadFound00;
				eDecodeState := PayloadDecodeStates.object_getboolean_value;
			ProtobufedId.Metric_string_value:
				eDecodeState := PayloadDecodeStates.object_getstring_value;
			ProtobufedId.Metric_bytes_value[0]:
			ProtobufedId.Metric_dataset_value[0]:
			ProtobufedId.Metric_template_value[0]:
			ProtobufedId.Metric_extension_value[0]:
				eDecodeError := ERROR.PayloadFoundExtensions;
			ELSE  //extension... error
			END_CASE
		PayloadDecodeStates.object_getname :
			_xHasName := TRUE;
			dviTemp := OwnerPayload.DecodeNextVarInt(); //updates i to end of the varint
			_uliTimestamp := dviTemp.uliDateTime;
		PayloadDecodeStates.object_gettype :
			_xHasDatatype := TRUE;
			_udiDatatype := dviTemp.UInt32;
		PayloadDecodeStates.object_getint_value :
			_eHasValue := MetricProtobufsType.int_value;
			_rValue  := OwnerPayload.DecodeNextFloat(); //updates i to end of the varint
		PayloadDecodeStates.object_getdouble_value :
			_eHasValue := MetricProtobufsType.double_value;
			_sValue  := OwnerPayload.DecodeNextString(); //updates i to end of the varint
        PayloadDecodeStates.object_getis_null : 
            _xHasIs_null := TRUE;
            eDecodeState := PayloadDecodeStates.object_getmember;
		END_CASE
	END_FOR
	IF NOT xDecodeError THEN
	xDecodeDone := NOT xDecodeError;
END_IF;
	//NOTE: BLOB Data will not be initialized to 00.
	//store the starting byte, because we need it right at the end
	//Encode Name (Field Number 1)
		{info 'todo: i-campbell Make these field numbers a GVL'}
		eEncodeError := OwnerPayload.EncodeNextString(ValueToEncode := _sName, ProtobufFieldNumber:= 1);
	END_IF;
	IF eEncodeError = ERROR.NO_ERROR AND _xHasAlias THEN
	//Encode Timestamp (Field Number 3)
		dviTemp.uliDateTime := _uliTimestamp;
		eEncodeError := OwnerPayload.EncodeNextVarInt(ValueToEncode := dviTemp, ProtobufFieldNumber:= 3);
	IF eEncodeError = ERROR.NO_ERROR AND _xHasDatatype THEN
	//Encode is_historical
		dviTemp.Boolean := _xIs_historical;
		eEncodeError := OwnerPayload.EncodeNextVarInt(ValueToEncode:= dviTemp, ProtobufFieldNumber:= 5);
	IF eEncodeError = ERROR.NO_ERROR AND _xHasIs_transient THEN
	//Encode is_null
		dviTemp.Boolean := _xIs_null;
		eEncodeError := OwnerPayload.EncodeNextVarInt(ValueToEncode:= dviTemp, ProtobufFieldNumber:= 7);
	//metadata fieldnumber
	//metadatavarints.bool * 12off
	IF eEncodeError = ERROR.NO_ERROR AND _xHasPropertySet THEN
			xDecode:= FALSE, 
			OwnerPayload:= OwnerPayload, 
			myProtobufBlob:= myProtobufBlob, 
			myPropertySetValuesPool:= myPropertySetValuesPool, 
			xDecodeDone=> , 
			xDecodeError=> , 
			xEncodeDone=> , 
			xEncodeError=> xEncodeError, 
	//encode Value
		CASE _eHasValue OF
		MetricProtobufsType.int_value, 
			xEncodeError := eEncodeError <> ERROR.NO_ERROR;
	    MetricProtobufsType.double_value:
			eEncodeError := OwnerPayload.EncodeNextDouble(ValueToEncode:= _lrValue, ProtobufFieldNumber:= TO_BYTE(_eHasValue));
	    MetricProtobufsType.bytes_value:
				StartOfBytes := _diStartOfBytes,